﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net.Sockets;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace client
{
    public partial class Form1 : Form
    {
        private Socket client;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //1.创建客户端，使用IPV4，字节流，TCP协议
            client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            //2.客户端连接服务端
            client.Connect(new IPEndPoint(IPAddress.Parse("192.168.1.10"), 6666));
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //向服务端发消息
            client.Send(Encoding.UTF8.GetBytes(textBox1.Text));

            //5.阻塞等待接收服务端消息
            byte[] bytes = new byte[1024];
            int v = client.Receive(bytes);
            label1.Text = Encoding.UTF8.GetString(bytes, 0, v);
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }
    }
}
